package com.kmproject.haifu.mvp.model;

import android.app.Application;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.google.gson.Gson;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.kmproject.haifu.mvp.contract.MapSelectAddressContract;
import com.kmproject.haifu.mvp.model.api.service.UserService;
import com.kmproject.haifu.mvp.model.entity.beans.GooglePlaceInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.GooglePlaceInfoTextSearchBean;

import javax.inject.Inject;

import io.reactivex.Observable;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 07/03/2019 00:44
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class MapSelectAddressModel extends BaseModel implements MapSelectAddressContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public MapSelectAddressModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<GooglePlaceInfoBean> nearbySearchRequest(@NonNull String url, @NonNull String key, @NonNull String lat, @NonNull String lng, @Nullable String pagetoken, int radius) {
        String location = lat + "," + lng;
        return mRepositoryManager.obtainRetrofitService(UserService.class).nearbySearchRequest(url, key, location, pagetoken, radius, "zh-CN");
    }

    @Override
    public Observable<GooglePlaceInfoTextSearchBean> keywordSearchRequest(@NonNull String url, @NonNull String key, @NonNull String keyword, String lat, String lng, @Nullable String pagetoken, int radius, @NonNull String region) {
        String location = null;
        if (!StringUtils.isEmpty(lat) && !StringUtils.isEmpty(lng)) {
            location = lat + "," + lng;
        }
        return mRepositoryManager.obtainRetrofitService(UserService.class).keywordSearchRequest(url, key, keyword, location, pagetoken, radius, "zh-CN", region,
                "lodging,accounting,airport,amusement_park,aquarium,art_gallery,atm,bakery,shopping_mall,point_of_interest,establishment,home_goods_store,hospital," +
                        "hospital,library,park,parking,restaurant,store,store,store,travel_agency,room,finance,street_address,street_number,postal_town");
    }
}